from django.shortcuts import render
from rest_framework import mixins, viewsets

from itsecure.api.ACapi import ACapi
from itsecure.models import DingTalkOAApproval
from itsecure.serializers import DingTalkOAApprovalSerializer
# Create your views here.
from rest_framework.response import Response
from rest_framework import status
from loguru import logger

from itsecure.api.ACapi import ACapi

logger.add("logtest/itlog.log", rotation="500 MB")  # 文件大小达到500MB时轮转
# logger.info('views file')

class DingTalkOAApprovalViewSet(viewsets.ModelViewSet):
# class DingTalkOAApprovalViewSet(viewsets.GenericViewSet, mixins.ListModelMixin, mixins.UpdateModelMixin, mixins.RetrieveModelMixin, mixins.CreateModelMixin):
    queryset = DingTalkOAApproval.objects.all()
    serializer_class = DingTalkOAApprovalSerializer

    def list(self, request, *args, **kwargs):
        print('I get the message ')
        logger.info("这是drf的list方法，列出所有对象")
        return super().list(request, *args, **kwargs)

    def retrieve(self, request, *args, **kwargs):
        logger.info("这是drf的retrieve方法，获取单个对象")
        return super().retrieve(request, *args, **kwargs)

    def update(self, request, *args, **kwargs):
        logger.info("这是drf的update方法，更新单个对象")
        return super().update(request, *args, **kwargs)
        # return Response({'message': 'update 方法'}, status=status.HTTP_200_OK)

    def create(self, request, *args, **kwargs):
        logger.info("这是drf的create方法，创建一个新的对象")
        print(request.data['message'])
        respond = ACapi(request.data).process_request()
        return super().create(request, *args, **kwargs)